#include "../freebsd_tail_queue.h"

#include <stdio.h>

struct student
{
  int id;
  TAILQ_ENTRY(student) tailq_next;
};

#define TAILQ_ENTRY_INIT(elm, field) \
  do                                 \
  {                                  \
    (elm)->field.tqe_next = NULL;    \
    (elm)->field.tqe_prev = NULL;    \
  } while (0)

int main()
{
  struct student stu0;
  struct student stu1;
  struct student stu2;
  struct student stu3;

  stu0.id = 0;
  stu1.id = 1;
  stu2.id = 2;
  stu3.id = 3;

  TAILQ_ENTRY_INIT(&stu0, tailq_next);
  TAILQ_ENTRY_INIT(&stu1, tailq_next);
  TAILQ_ENTRY_INIT(&stu2, tailq_next);
  TAILQ_ENTRY_INIT(&stu3, tailq_next);

  TAILQ_HEAD(, student) stu_head;

  TAILQ_INSERT_HEAD(&stu_head, &stu0, tailq_next);
  TAILQ_INSERT_HEAD(&stu_head, &stu1, tailq_next);
  TAILQ_INSERT_HEAD(&stu_head, &stu2, tailq_next);
  TAILQ_INSERT_HEAD(&stu_head, &stu3, tailq_next);

  struct student *stu_iter;
  TAILQ_FOREACH(stu_iter, &stu_head, tailq_next)
  {
    printf("%d ", stu_iter->id);
  }
}
